﻿
using KinectWindowLib;
using KinectWindowLib.Graphics;
using KinectWindowLib.NuiControls;
using KinectWindowLib.WIndows;
using KinectWindows.Math;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using KinectWindowLib.Windows;

namespace KinectWindows.Windows
{
    public delegate void OnPaint(NuiWindow display);
    // Repesent all Windows and controls that are drived from VtkProp
    public class NuiWindow
    {
        #region static Creator for a simple window that contain no children just backgrounds
       

        public static NuiWindow CreateSimpleWindow(Screen screen, Vector2 Location, Vector2 Dimentions)
        {
                        
            WindowAttribute attr=new WindowAttribute();
            attr.Location = Location;
            attr.Dimentions = Dimentions;
            attr.Class = WindowClass.WC_SIMPLE_WINDOW;
            attr.Boarder_width = 1;
            attr.Show_Titile_bar = true;
            attr.Show_Status_bar = true;
          
            return NuiWindow.CreateWindow(screen,attr);
        }
        /// <summary>
        /// Create the Root Window That All Other Windows Will be Drawon on The top if it
        /// </summary>
        /// <param name="screen"></param>
        /// <returns></returns>
        public static NuiWindow CreateRootWindow(Screen screen)
        {

            WindowAttribute attr = new WindowAttribute();
            attr.Location = Vector2.Zero;
            attr.Dimentions = new Vector2(screen.Bounds.Width,screen.Bounds.Width);
            attr.Class = WindowClass.WC_ROOT;
            attr.Boarder_width = 0;
            attr.Show_Titile_bar = false;
            attr.Show_Status_bar = false;
            attr.ParentId = 0;
            attr.BackGroundColor = Color.White;
            return NuiWindow.CreateWindow(screen, attr);
        }
        public static NuiWindow CraeteDialogBox(Screen screen, Vector2 Location, Vector2 Dimentions)
        {
            WindowAttribute attr = new WindowAttribute();
            attr.Location = Location;
            attr.Dimentions = Dimentions;
            attr.Class = WindowClass.WC_DIALOG_BOX;
            attr.Boarder_width = 1;
            attr.Show_Titile_bar = false;
            attr.Show_Status_bar = false;

            return NuiWindow.CreateWindow(screen, attr);
        }
        public static NuiWindow CreateWindow(Screen screen, WindowAttribute attr)
        {
            GraphicContext gc = new GraphicContext();
            gc.CreateGC(screen);
            NuiWindow nui = new NuiWindow();
            nui.WindowAttributes = attr;
            nui.GCContext = gc;
            return nui;
        }




        #endregion

        public List<NuiWidget> Children { set; get; }
        #region Delegates
        public OnPaint onPaint;        
        #endregion
        private WindowInfo Info;
        public GraphicContext GCContext { set; get; }

       
        public NuiWindow()
        {
            // TODO: Complete member initialization
            WindowInfo _Info = new WindowInfo();            
            _Info.border_width = 1;
            _Info.Background = Colormap.Create(0x00, 0xff, 0xff, 0xff);
            Info = _Info;
            
            Children = new List<NuiWidget>();
        }


        // Paint the Control on The VTK Stage
        internal virtual void OnDraw(Display display)
        {
            Paint(Info.screen);
           
        }
        // Paint the Control
        internal virtual void Paint(Screen display)
        {
            DrawWindow();

            if (Children.Count > 0)
            {
                for (int i = 0; i < Children.Count; i++)
                    Children[i].OnDraw(display);
            }

            onPaint(this);
        }

        // Add a new Window to the screen
        public void Add(NuiWidget wind)
        {
            Children.Add(wind);
        }

        #region window Propraties
        public float Left { set { Info.x = value; } get { return Info.x; } }
        public float Top { set { Info.y = value; } get { return Info.y; } }
        public float Width { get { return Info.width; } set { Info.width = value; } }
        public float Height { get { return Info.height; } set { Info.height = value; } }
        public String Name { set { Info.Name = value; } get { return Info.Name; } }
        public long Id { set { Info.Id = value; } get { return Info.Id; } }
        public Object Tag { set { Info.Tag = value; } get { return Info.Tag; } }
        
        #endregion
        #region for internal use
        // Draw the window
        protected void DrawWindow()
        {
            DrawBackground();
            DrawBoarders();
           
        }
        // Draw the Window Background
        private void DrawBackground()
        {
           
        }

        // Draw the Window Boarder
        private void DrawBoarders()
        {
        }
        
        #endregion


        internal WindowAttribute WindowAttributes { get; set; }
    }
    [Flags]
    public enum WindowClass
    {
        WC_IDLE, // IDLE WINDOW IS A WINDOW WITH A TITLEBAR CLOSE BUTTON AND DO NOT INTERACT WITH NUI SIGNALS
        WC_SIMPLE_WINDOW,
        WC_DIALOG_BOX,
        WC_ROOT
    }
}
